package jschool.ui.Asistencia;

import java.awt.Color;
import java.awt.Rectangle;

import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;

import jschool.modelos.ModeloDeAsistencia;

public class PanelAsistencia extends JPanel {

	private static final long serialVersionUID = 1L;
	private JLabel lblCurso = null;
	private JLabel lblNombreCurso = null;
	private JLabel lblEstudiante = null;
	private JPanel panelLista = null;
	private JScrollPane jspListaEstudiantes = null;
	private JTable tblListaEstudiantes = null;
	private ModeloDeAsistencia modelo = null;
	private float medida;

	/**
	 * This is the default constructor
	 */
	public PanelAsistencia() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		
		modelo = ModeloDeAsistencia.getInstancia();
		lblEstudiante = new JLabel();
		lblEstudiante.setBounds(new Rectangle(62, 49, 316, 20));
		lblEstudiante.setText("Estudiantes");
		lblEstudiante.setHorizontalAlignment(SwingConstants.CENTER);
		lblNombreCurso = new JLabel();
		lblNombreCurso.setBounds(new Rectangle(62, 12, 183, 20));
		lblNombreCurso.setText("");
		lblCurso = new JLabel();
		lblCurso.setBounds(new Rectangle(13, 12, 44, 20));
		lblCurso.setText("Curso:");
		this.setLayout(null);
		this.add(lblCurso, null);
		this.add(lblNombreCurso, null);
		this.add(getPanelLista(), null);
		int width = (int) (50 + medida);
		
		this.setSize(599, width);
	}

	/**
	 * This method initializes panelLista
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getPanelLista() {
		if (panelLista == null) {
			panelLista = new JPanel();
			panelLista.setLayout(new BoxLayout(getPanelLista(),
					BoxLayout.X_AXIS));
			medida = 17f * (modelo.getRowCount() + 1);

			panelLista.setBounds(new Rectangle(13, 39, 578, (int) medida));
			panelLista.add(getJspListaEstudiantes(), null);
		}
		return panelLista;
	}

	/**
	 * This method initializes jspListaEstudiantes
	 * 
	 * @return javax.swing.JScrollPane
	 */
	private JScrollPane getJspListaEstudiantes() {
		if (jspListaEstudiantes == null) {
			jspListaEstudiantes = new JScrollPane();
			jspListaEstudiantes.setViewportView(getTblListaEstudiantes());
		}
		return jspListaEstudiantes;
	}

	/**
	 * This method initializes tblListaEstudiantes
	 * 
	 * @return javax.swing.JTable
	 */
	private JTable getTblListaEstudiantes() {
		if (tblListaEstudiantes == null) {
			tblListaEstudiantes = new JTable();
			tblListaEstudiantes
					.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
			tblListaEstudiantes.setBackground(new Color(254, 254, 255));
			tblListaEstudiantes.setModel(modelo);
			modelo.disminuirColumna(tblListaEstudiantes);
			tblListaEstudiantes.setShowVerticalLines(false);
			tblListaEstudiantes.setCellSelectionEnabled(false);
			tblListaEstudiantes.setColumnSelectionAllowed(false);
			tblListaEstudiantes.setFocusable(false);
			Color color = this.getBackground();
			tblListaEstudiantes.setGridColor(color);
			DefaultTableCellRenderer tableRenderer = new DefaultTableCellRenderer();
			tableRenderer.setHorizontalAlignment(SwingConstants.CENTER);
			tblListaEstudiantes.getColumnModel().getColumn(0).setCellRenderer(
					tableRenderer);
			tblListaEstudiantes.getColumnModel().getColumn(1).setCellRenderer(
					tableRenderer);

		}
		return tblListaEstudiantes;
	}

} // @jve:decl-index=0:visual-constraint="10,10"
